#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
//#define addr(l , r) (((l) + (r)) | ((l) != (r)))

using namespace std;

int n;
int l[1000], r[1000];

struct Tevent
{
	int pos, id, type;

	Tevent ()
	{
	}

	Tevent (int pos1, int id1, int type1)
	{
		pos = pos1;
		id = id1;
		type = type1;
	}
} data[2000];
int start;
int dp;

int marx[15000], flag[15000];

bool operator < (const Tevent& a, const Tevent& b)
{
	return (a.pos >= start? a.pos : a.pos + 1440) < (b.pos >= start? b.pos : b.pos + 1440);
}

inline int getmarx (int a, int b)
{
	return a > b? a : b;
}

int account = 0;

void chg (int l, int r, int ll, int rr, int x, int p)
{
	account ++;
//	if (account % 100000 == 0)
//		printf("oops! %d\n", account);
	if (l == ll && r == rr)
	{
		flag[p] += x;
		marx[p] += x;
	}
	else
	{
		int m = (l + r) / 2;

/*		flag[addr(l, m)] += flag[addr(l, r)];
		flag[addr(m+1, r)] += flag[addr(l, r)];
		flag[addr(l, r)] = 0;*/

		flag[p << 1] += flag[p];
		flag[(p << 1) | 1] += flag[p];
		flag[p] = 0;

		if (ll <= m)
			chg(l, m, ll, rr < m? rr : m, x, p << 1);
		if (rr >= m + 1)
			chg(m + 1, r, ll > m + 1? ll : m + 1, rr, x, (p << 1) | 1);
//		marx[addr(l, r)] = getmarx(marx[addr(l, m)], marx[addr(m + 1, r)]);
		marx[p] = getmarx(marx[p << 1], marx[(p << 1) | 1]);
	}
}

int contains (int id, int pos)
{
	return (pos >= l[id] && pos < r[id] ||  l[id] > r[id] && (pos >= l[id] || pos < r[id]));
}

void addEvent (int pos, int id,  int type)
{
	data[dp ++] = Tevent (pos, id, type);
}

void addSegment (int who, int x)
{
	if (l[who] < r[who])
		chg(0, 1439, l[who], r[who] - 1, x, 1);
	else
	{
		if (r[who] != 0)
			chg(0, 1439, 0, r[who] - 1, x, 1);
		chg(0, 1439, l[who], 1439, x, 1);
	}
}

int main ()
{
	char buf[50];

	int ct = 0;

	while (scanf("%d", &n) > 0 && n > 0)
	{
		account = 0;
		for (int i = 0; i < n; i ++)
		{
			int a, b, c, d;

			scanf("%s", buf);

			a = (buf[0] - '0') * 10 + (buf[1] - '0');
			b = (buf[3] - '0') * 10 + (buf[4] - '0');
			c = (buf[6] - '0') * 10 + (buf[7] - '0');
			d = (buf[9] - '0') * 10 + (buf[10] - '0');
/*
			a = rand() % 24;
			b = rand() % 60;
			c = rand() % 24;
			d = rand() % 60;
*/
			a %= 24;
			c %= 24;
			l[i] = a * 60 + b;
			r[i] = c * 60 + d;

//			printf("%d %d\n", l[i], r[i]);
		}
		
		int ans = 0;

		for (int i = 0; i < 1440; i ++)
		{
			int cur = 0;
			for (int j = 0; j < n; j ++)
				if (contains(j, i))
					cur ++;
			if (cur > ans)
				ans = cur;
		}

		for (int i = 0; i < 1440; i ++)
		{
			dp = 0;
			int cur = 0;
			for (int j = 0; j < n; j ++)
				if (contains(j, i))
				{
					addEvent (l[j], j, 12);
					addEvent (r[j], j, 13);

					cur ++;
				}
				else
				{
					addEvent (l[j], j, 23);
					addEvent (r[j], j, 00);
				}
			
			start = (i + 1) % 1440;
			sort (data, data + dp);

			memset(marx, 0, sizeof(marx));
			memset(flag, 0, sizeof(flag));

			for (int j = 0; j < dp; j ++)
			{
				if (data[j].pos < i)
					break;
				if (data[j].type == 12)
				{
					cur ++;
					addSegment(data[j].id, -1);
				}
				else if (data[j].type == 13)
				{
					cur --;
					addSegment(data[j].id, 1);
				}
				else if (data[j].type == 23)
				{
					addSegment(data[j].id, 1);
				}
				else
				{
					addSegment(data[j].id, -1);
				}
				if ((j == dp - 1 || data[j].pos != data[j + 1].pos) && cur + marx[1] > ans)
					ans = cur + marx[1];
			}
		}

		printf("Case %d: %d\n", ++ ct, ans);
	}

	return 0;
}